namespace hjc {

	export class ProxyManager extends Singleton implements ILaunchable {

		private $proxies: Proxy[] = [];

		public launch(options: LaunchOptions): void {
			if (notEmptyArr(options.Proxies))
				options.Proxies.unique().forEach((proxyClass: new () => Proxy) => this.$proxies.push(new proxyClass()));
		}

		public get<P extends Proxy>(clazz: new () => P): P {
			for (let proxy of this.$proxies) {
				if (proxy instanceof clazz) return proxy;
			}
			let proxy = new clazz();
			this.$proxies.push(proxy);
			return proxy;
		}

		public resetAll(): void {
			this.$proxies.forEach(proxy => proxy.reset());
		}

		public getAll(): Proxy[] { return this.$proxies; }
	}
}